package com.dqyz.web.controller.busi;

import com.dqyz.busi.domain.Competition;
import com.dqyz.busi.domain.vo.CompetitionVo;
import com.dqyz.busi.service.ICompetitionService;
import com.dqyz.common.annotation.Log;
import com.dqyz.common.core.controller.BaseController;
import com.dqyz.common.core.domain.AjaxResult;
import com.dqyz.common.core.page.TableDataInfo;
import com.dqyz.common.enums.BusinessType;
import com.dqyz.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 赛事管理Controller
 * 
 * @author wangguan
 * @date 2024-09-27
 */
@RestController
@RequestMapping("/busi/competition")
public class CompetitionController extends BaseController
{
    @Autowired
    private ICompetitionService competitionService;

    /**
     * 查询赛事管理列表
     */
    @PreAuthorize("@ss.hasPermi('busi:competition:list')")
    @GetMapping("/list")
    public TableDataInfo list(Competition competition)
    {
        startPage();
//        List<Competition> list = competitionService.selectCompetitionList(competition);
        List<CompetitionVo> list = competitionService.selectCompetitionVoList(competition);
        return getDataTable(list);
    }

    /**
     * 导出赛事管理列表
     */
    @PreAuthorize("@ss.hasPermi('busi:competition:export')")
    @Log(title = "赛事管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Competition competition)
    {
        List<Competition> list = competitionService.selectCompetitionList(competition);
        ExcelUtil<Competition> util = new ExcelUtil<Competition>(Competition.class);
        util.exportExcel(response, list, "赛事管理数据");
    }

    /**
     * 获取赛事管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('busi:competition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(competitionService.selectCompetitionById(id));
    }

    /**
     * 赛事发布
     */
    @PreAuthorize("@ss.hasPermi('busi:competition:edit')")
    @GetMapping(value = "/publish/{id}")
    public AjaxResult publishCompetition(@PathVariable("id") Long id)
    {
        return success(competitionService.publishCompetitionById(id));
    }

    /**
     * 新增赛事管理
     */
    @PreAuthorize("@ss.hasPermi('busi:competition:add')")
    @Log(title = "赛事管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Competition competition)
    {
        return toAjax(competitionService.insertCompetition(competition));
    }

    /**
     * 修改赛事管理
     */
    @PreAuthorize("@ss.hasPermi('busi:competition:edit')")
    @Log(title = "赛事管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Competition competition)
    {
        return toAjax(competitionService.updateCompetition(competition));
    }

    /**
     * 删除赛事管理
     */
    @PreAuthorize("@ss.hasPermi('busi:competition:remove')")
    @Log(title = "赛事管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(competitionService.deleteCompetitionByIds(ids));
    }
}
